#include "Motor_Control.h"
#include "tim.h"


void Motor_Init(void){
    HAL_TIM_Base_Start_IT(&htim6);                      //pid计算定时器
    HAL_TIM_PWM_Start(&htim15,TIM_CHANNEL_1);    //电机1
    HAL_TIM_PWM_Start(&htim15,TIM_CHANNEL_2);
}
void Motor_Control(PID_Controller *pid,int16_t Motor_1)
{
    static float Input = 0.0f;
    if (pid == NULL) {
        return;
    }
    PID_SetSetpoint(pid,Motor_1);
    Input = pid->output;
    if (pid->output >= 0){
        __HAL_TIM_SET_COMPARE(&htim15,TIM_CHANNEL_1,(int16_t)Input);
        __HAL_TIM_SET_COMPARE(&htim15,TIM_CHANNEL_2,0);}
    else{
        __HAL_TIM_SET_COMPARE(&htim15,TIM_CHANNEL_1,0);
        __HAL_TIM_SET_COMPARE(&htim15,TIM_CHANNEL_2,(int16_t)(-Input));
    }
}
